﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace PizzaLunch
{
    public class LoggerFile
    {
        public enum LoggerLevel
        {
            LoggerNone = 0,
            LoggerError,
            LoggerWaring,
            LoggerProcessing,
            LoggerInformation,
            LoggerDetail,
            LoggerDebug,
        }

        private string _fileName;
        public string FileName { get { return _fileName; } }
        private LoggerLevel _showLevel;
        public LoggerLevel ShowLevel { get { return _showLevel; } }

        public LoggerFile(string Name, LoggerLevel Level)
        {
            _fileName = Name;
            _showLevel = Level;
        }

        public void WriteLog(string Content,LoggerLevel WriteLevel)
        {
            if (WriteLevel > ShowLevel || string.IsNullOrEmpty(Content) || string.IsNullOrEmpty(FileName))
                return;
            lock (this)
            {
                StreamWriter sw = File.AppendText(FileName);
                sw.WriteLine(DateTime.Now.ToString());
                sw.WriteLine("[" + WriteLevel.ToString() + "] - " + Content);
                sw.Flush();
                sw.Close();
            }
        }
    }
}
